package com.chen.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chen.entity.Teacher;
import com.chen.vo.TeacherVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 教师Mapper
 */
public interface TeacherMapper extends BaseMapper<Teacher> {

    /**
     * 通过教师账号和密码查询教师信息
     * 教师登陆时使用
     * @param account 教师账号
     * @param pwd 教师密码
     * @return
     */
    default Teacher findTeacherByAccountAndPwd(String account, String pwd) {
        Wrapper<Teacher> queryWrapper = Wrappers.lambdaQuery(Teacher.class).eq(Teacher::getAccount, account).eq(Teacher::getPwd, pwd);
        return selectOne(queryWrapper);
    }

    /**
     * 查找isWork为0的教师信息， 即非班主任教师
     * @return
     */
    default List<Teacher> findTeachersByIsWorkZero() {
        Wrapper<Teacher> queryWrapper = Wrappers.lambdaQuery(Teacher.class).eq(Teacher::getIsWork, 0);
        return selectList(queryWrapper);
    }

    /**
     * 总教师人数
     * @return
     */
    default Long findAllCount() {
        return selectCount(Wrappers.lambdaQuery(Teacher.class));
    }

    /**
     * 分页查询教师信息
     * @param index
     * @param pageShow
     * @return
     */
    List<TeacherVO> listPage(@Param("index") Integer index, @Param("pageShow") Integer pageShow);

    /**
     * 根据教师id获取教师信息
     * @param id
     * @return
     */
    TeacherVO getTeacherById(Integer id);

}
